$(function () {
    vm.getnumber();
    $("#jqGrid").jqGrid({
        url: baseURL + 'gaokaobaobei/agency/list2',
        datatype: "json",

        colModel: [
            { label: '招生人员', name: 'name', index: 'name', width: 60 },
            { label: '单位', name: 'unit', index: 'unit', width: 100 },
            { label: '联系电话', name: 'phone', index: 'phone', width: 80 },
            { label: '审核通过', name: 'accessCount', index: 'accessCount', width: 80 },
            { label: '审核未通过', name: 'noSuccessAuditCount', index: 'noSuccessAuditCount', width: 80 },
            { label: '等待审核', name: 'noAuditCount', index: 'noAuditCount', width: 80 },
            { label: '已过期', name: 'expireCount', index: 'expireCount', width: 80},
            { label: '等待录取结果', name: 'waitResultCount', index: 'waitResultCount', width: 80 },
            // { label: '未提交', name: 'noSubmitCount', index: 'noSubmitCount', width: 80 },
            { label: '个人业绩(考研)',  width: 80,
                formatter:function (data,a,rows) {
                    return '<button class="btn btn-success" onclick="agency(\''+rows.name+'\')">审核业绩</button>'
                }

            }
        ],

		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

function agency(name) {
    var data = "name=" +name+"&type=1";
    var url = "gaokaobaobei/agency/saveName";
    $.ajax({
        type: "POST",
        url: baseURL + url,
        data: data,
        success:function () {
            window.location.href="PerformanceAudit.html"
        }
    });
}

function select(name,num) {
    var data = "name=" +name+"&type=d";
    var url = num==0? "gaokaobaobei/agency/selectNumber":"gaokaobaobei/agency/selectSum";
    $.ajax({
        type: "POST",
        url: baseURL + url,
        data: data,
        success:function (data) {
            if(num==0){

                alert("代理人数为:"+data.number+"人");
            }else  {
                alert("代理人单招通过总人数为:"+data.sum+"人");
            }
        }
    });
}

var vm = new Vue({
    el: '#rrapp',
    data: {
        showList: true,
        title: null,
        agency: {},
        msg:null
    },
    methods: {
        getnumber:function () {

            var url = "gaokaobaobei/agency/getNumberkaoyan";
            $.ajax({
                type: "POST",
                url: baseURL + url,
                success: function(r){
                    console.log(r)
                    vm.msg = r.msg;
                }
            });

        },
        query: function () {
            vm.reload();
        },
        add: function () {
            vm.showList = false;
            vm.title = "新增";
            vm.agency = {};
        },
        update: function (event) {
            var id = getSelectedRow();
            if (id == null) {
                return;
            }
            vm.showList = false;
            vm.title = "修改";

            vm.getInfo(id)
        },
        saveOrUpdate: function (event) {
            var url = vm.agency.id == null ? "gaokaobaobei/agency/save" : "gaokaobaobei/agency/update";
            $.ajax({
                type: "POST",
                url: baseURL + url,
                contentType: "application/json",
                data: JSON.stringify(vm.agency),
                success: function (r) {
                    if (r.code === 0) {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
                    } else {
                        alert(r.msg);
                    }
                }
            });
        },
        del: function (event) {
            var ids = getSelectedRows();
            if (ids == null) {
                return;
            }

            confirm('确定要删除选中的记录？', function () {
                $.ajax({
                    type: "POST",
                    url: baseURL + "gaokaobaobei/agency/delete",
                    contentType: "application/json",
                    data: JSON.stringify(ids),
                    success: function (r) {
                        if (r.code == 0) {
                            alert('操作成功', function (index) {
                                $("#jqGrid").trigger("reloadGrid");
                            });
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            });
        },
        getInfo: function (id) {
            $.get(baseURL + "gaokaobaobei/agency/info/" + id, function (r) {
                vm.agency = r.agency;
            });
        },
        reload: function (event) {
            vm.showList = true;
            vm.getnumber();
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                page: page
            }).trigger("reloadGrid");
        }
    }

});